import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {FormGroup, FormControl, Validators, FormBuilder} from '@angular/forms';

@Component({
  selector: 'app-backend-nav-bar',
  templateUrl: './backend-nav-bar.component.html',
  styleUrls: ['./backend-nav-bar.component.scss']
})
export class BackendNavBarComponent implements OnInit {
  searchForm: FormGroup;
  keyword = new FormControl('', [
    Validators.required,
    Validators.minLength(5),
    Validators.maxLength(20)
  ]);

  notification = false;
  searchInputFocus = false;

  setSearchInputFocus() {
    this.searchInputFocus = true;
  }

  setSearchInputBlur() {
    this.searchInputFocus = false;
  }

  setClassSearch() {
    return !this.keyword.pristine && !this.keyword.valid;
  }

  constructor(private formBuilder: FormBuilder,
              private router: Router) {
  }

  toggleNotification() {
    this.notification = !this.notification;
  }

  ngOnInit() {
    this.searchForm = this.formBuilder.group({
      keyword: this.keyword
    });
  }

  search() {
    this.router.navigate(['/admin/dashboard']);
  }
}
